#include<iostream>
using namespace std;
struct TreeNode{
	TreeNode* left;
	TreeNode* right;
	char data;
};
int GetHeight( TreeNode *Node ){
	int l,r,max;
	if(Node==NULL)return 0;
	else{
		l=GetHeight(Node->left);
		r=GetHeight(Node->right);
		if(l>r)max=l;
		else max=r;
		return (max+1);
	}
}
TreeNode*findTree(char*pre,char*in,int length)  
{  
    if(length==0)  return NULL;  
    TreeNode* node=new TreeNode;  
    node->data=*pre;  
    int i=0;  
    for(;i<length;i++)  
    {  
        if(in[i]==*pre)  
        break;  
    }  
    node->left=findTree(pre+1,in,i);  
    node->right=findTree(pre+i+1,in+i+1,length-i-1);  
    return node;  
} 
	 

int main()
{
	int n,i;
	cin>>n;
	char pre[1000],in[1000];
	char c;
	for(i=0;i<n;i++){
		cin>>c;
		pre[i]=c;
	}
	for(i=0;i<n;i++){
		cin>>c;
		in[i]=c;
	}
	TreeNode* Node=new TreeNode;  
    Node=findTree(pre,in,n);  
	cout<<GetHeight(Node)<<endl;
}

